let mongoose = require('mongoose');

let schema = new mongoose.Schema({
    // appClickEvents:{ //其他app导流点击事件
    //     type:[require('./gameUser.clickEvent.item')],
    //     default:[]
    // }
    appIds:{
        type:Array,
        default:[]
    }
});

schema.methods={
    click:async function(options={group:''}){
        let ClickEventModel=mongoose.models['ClickEvent'];
        await ClickEventModel.create({
            timeTick:new Date().getTime(),
            data:!!options.data?options.data:{},
            group:options.group,
            userId:options.self._id.toString()
        });
    },
    //app点击事件，加入去重机制
    appClick:async function(options={appId:'',sceneName:'',area:''}){
        if(this.appIds.indexOf(options.appId)<0){
            this.appIds=[].concat(this.appIds,[options.appId]);
            this.click({
                data:{
                    appId:options.appId,
                    sceneName:options.sceneName,
                    area:options.area
                },
                self:options.self,
                group:'友情链接点击去重统计'
            });
        }
        this.click({
            data:{
                appId:options.appId,
                sceneName:options.sceneName,
                area:options.area
            },
            self:options.self,
            group:'友情链接点击统计'
        });
    }
};

module.exports=schema;